var FramesetInstaller = Base.extend({
	constructor: function()
	{
		FramesetInstaller.instance = this;
	},
	IsFrameset: function()
	{
		// look for the number of frameset node... 
		// since window.frames.length counts iframe
		var node = document.getElementsByTagName('frameset');

		if(node.length == 0) return false;
		else return true;
	},
	SelectLargestAreaFrame: function()
	{
		// special case for IE
		if(GownFullBrowserDetect.current_browser == GownFullBrowserDetect.BROWSER_IE) {
			var frs = document.getElementsByTagName('frame');
			var i,name;
			var fre,area;
			var largest = null;
			var largest_area = 0;
			var width,height;

			for(i=0;i<frs.length;i++) {
				name = frs.item(i).name;
				fre = window.frames[name];
				width = height = 0;
				width = (width == 0 && fre.document.documentElement) ? fre.document.documentElement.clientWidth : width;
				width = (width == 0 && fre.document.body) ? fre.document.body.clientWidth : width;
				height = (height == 0 && fre.document.documentElement) ? fre.document.documentElement.clientHeight : height;
				height = (height == 0 && fre.document.body) ? fre.document.body.clientHeight : height;
				try {
					area = width * height;
				}
				catch(e) {
					area = 0;
				}
	
				if(area > largest_area) {
					largest_area = area;
					largest = fre;
				}
			}
			return largest;
		}
		else {
			var i,fre,area;
			var largest = null;
			var largest_area = 0;
	
			for(i=0;i<window.frames.length;i++) {
				fre = window.frames[i];
				//var str = fre.innerWidth + 'x' + fre.innerHeight;
				//alert(str);
				try {
					area = fre.innerWidth * fre.innerHeight;
				}
				catch(e) {
					area = 0;
				}
	
				if(area > largest_area) {
					largest_area = area;
					largest = fre;
				}
			}
			return largest;
		}
	},
	InstallGownFull: function(target_frame)
	{
		try { // Probably permission denied if the frame is cross-domain
			var node = target_frame.document.createElement('script');
			node.type = 'text/javascript';
			node.src = FramesetInstaller.code_url;
			target_frame.document.body.appendChild(node);
			return true;
		}
		catch(e) {
			alert(e);
			return false;
		}
	}
},
{
	instance: null,
	code_url: null
});

new FramesetInstaller;
